<template>
  <div class="app-container">
    <div>
      <el-button
      size="mini"
      type="danger"
      @click="deleteByIdBath">批量删除</el-button>
    </div>
    <el-table
      :data="list"
      style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column
      type="selection"
      width="55">
      </el-table-column>
      <el-table-column
        prop="hosname"
        label="医院名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="hoscode"
        label="医院编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="signKey"
        label="签名秘钥">
      </el-table-column>
      <el-table-column
      prop="contactsName"
      label="联系人姓名">
    </el-table-column>
      <el-table-column
      prop="contactsPhone"
      label="联系人手机">
    </el-table-column>
    <el-table-column
      prop="status"
      label="状态"
      >
      <template slot-scope="scope">
        {{scope.row.status==1?"可用":"不可用"}}
      </template>
      </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <router-link :to="'edit/'+scope.row.id" >
          <el-button type="primary" size="mini" icon="el-icon-edit"></el-button>
        </router-link>
        <el-button
          v-if="scope.row.status==1"
          size="mini"
          @click="lock(scope.row.id,0)">锁定</el-button>
        <el-button
        v-if="scope.row.status==0"
        size="mini"
        @click="lock(scope.row.id,1)">解锁</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="deleteById(scope.row.id)">删除</el-button>
      </template>
    </el-table-column>
    </el-table>
    
    <el-pagination
      style="padding: 30px 0;text-align: center;"
      layout="prev, pager, next"
      :total="total"
      :current-page="current"
      :page-size="limit"
      @current-change="handlePageChange"
    />
    
  </div>
</template>

<script>
import hospitalSet from '@/api/hosp/hospitalSet'

export default {
  data() {
    return {
      total:0,
      current:1,
      limit:3,
      searchObj:{},
      list:[],
      selectedItems:[]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleSelectionChange(val) {
      this.selectedItems = val;
    },
    handlePageChange(val) {
      this.current=val;
      this.getList();
    },
    getList(){
      hospitalSet.hospitalSetList(this.current,this.limit,this.searchObj)
      .then(response =>{
        console.log("成功"),
        console.log(response),
        this.total=response.data.total,
        this.limit=response.data.size,
        this.current=response.data.current,
        this.list=response.data.records
        console.log("total:"+this.total+",limit:"+this.limit+",current:"+this.current) 
      })
      .catch(error => {
        console.log(error)
      })
    },
    deleteById(id){ 
      console.log(id)
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          hospitalSet.removeHospitalSet(id)
          .then(response =>{
            this.getList();
            console.log("成功"),
            console.log(response),
            console.log(response.message)
          })
          .catch(error => {
            console.log(error)
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    deleteByIdBath(){ 
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let idList=[]
          for(let i=0;i<this.selectedItems.length;i++){
            idList.push(this.selectedItems[i].id)
          }
          hospitalSet.removeHospitalSetBath(idList)
          .then(response =>{
            this.getList();
            console.log("成功"),
            console.log(response),
            console.log(response.message)
          })
          .catch(error => {
            console.log(error)
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    lock(id,status){
      hospitalSet.lockHospitalSet(id,status)
      .then(response =>{
        if(response.code==200){
          this.$message({
          message: response.message,
          type: 'success'
         })
         this.getList()
        }else{
          this.$message.error(response.message);
        }
      })
      .catch(e=>{
        console.log(response)
      })
    }
  }
}
</script>
